//
//  ActivityDetailView.m
//  豆瓣
//
//  Created by dllo on 15/12/9.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ActivityDetailView.h"
#import "UIImageView+WebCache.h"

@interface ActivityDetailView ()

@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UILabel *begin_timeLabel;
@property (nonatomic, retain) UILabel *end_timeLabel;
@property (nonatomic, retain) UILabel *organizersLabel;
@property (nonatomic, retain) UILabel *addressLabel;
@property (nonatomic, retain) UILabel *styleLabel;
@property (nonatomic, retain) UIImageView *activeImageView;
@property (nonatomic, retain) UILabel *introduceLabel;
@property (nonatomic, retain) UILabel *informationLabel;

@end

@implementation ActivityDetailView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)dealloc{
    [_nameLabel release];
    [_begin_timeLabel release];
    [_end_timeLabel release];
    [_organizersLabel release];
    [_addressLabel release];
    [_styleLabel release];
    [_activeImageView release];
    [_informationLabel release];
    [_introduceLabel release];
    [super dealloc];
}


- (void)setActivity:(ActivityList *)activity{
    if (_activity != activity) {
        [_activity release];
        _activity = [activity retain];
    }
    NSURL *url = [NSURL URLWithString:self.activity.image_hlarge];
    
    [self.activeImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"picholder"]];
    self.nameLabel.text = self.activity.title;
    self.begin_timeLabel.text = self.activity.begin_time;
    self.end_timeLabel.text = self.activity.end_time;
    self.organizersLabel.text = [self.activity.owner objectForKey:@"name"];
    self.styleLabel.text = self.activity.category_name;
    self.addressLabel.text = self.activity.address;
    [self.addressLabel sizeToFit];
    self.informationLabel.text = self.activity.content;
    [self.informationLabel sizeToFit];
}


- (void)createSubviews{
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
    scrollView.backgroundColor = [UIColor whiteColor];
    scrollView.contentSize = CGSizeMake(375, 667 *2);
    [self addSubview:scrollView];
    
    // 活动名Label
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 335, 36)];
    //    self.nameLabel.backgroundColor = [UIColor redColor];
    [self.nameLabel setNumberOfLines:0];
    self.nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
    [scrollView addSubview:self.nameLabel];
    [_nameLabel release];
    
    // 图片
    self.activeImageView =[[UIImageView alloc]initWithFrame:CGRectMake(20, 80, 120, 150)];
    self.activeImageView.backgroundColor = [UIColor redColor];
    //    [self.activeImageView setImage:[UIImage imageNamed:@"22.png"]];
    [scrollView addSubview:self.activeImageView];
    [_activeImageView release];
    
    // 活动时间的小图标
    UIImageView *timeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 80, 20, 20)];
    [timeImageView setImage:[UIImage imageNamed:@"icon_date_blue"]];
    [scrollView addSubview:timeImageView];
    [timeImageView release];
    
    // 开始
    UILabel *start = [[UILabel alloc] initWithFrame:CGRectMake(170, 80, 70, 20)];
    //    start.backgroundColor = [UIColor cyanColor];
    start.text = @"开始时间:";
    start.font = [UIFont systemFontOfSize:12];
    [scrollView addSubview:start];
    [start release];
    
    // 活动开始时间Label
    self.begin_timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(230, 80, 200, 20)];
    //    self.begin_timeLabel.backgroundColor = [UIColor redColor];
    self.begin_timeLabel.font = [UIFont systemFontOfSize:12];
    [scrollView addSubview:self.begin_timeLabel];
    [_begin_timeLabel release];
    
    // 结束
    UILabel *end = [[UILabel alloc] initWithFrame:CGRectMake(170, 100, 70, 20)];
    //    end.backgroundColor = [UIColor cyanColor];
    end.text = @"结束时间:";
    end.font = [UIFont systemFontOfSize:12];
    [scrollView addSubview:end];
    [end release];
    
    // 活动结束时间Label
    self.end_timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(230, 100, 200, 20)];
    //    self.end_timeLabel.backgroundColor = [UIColor redColor];
    self.end_timeLabel.font = [UIFont systemFontOfSize:12];
    [scrollView addSubview:self.end_timeLabel];
    [_end_timeLabel release];
    
    // 举办方小图标
    UIImageView *organizersImageView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 130, 20, 20)];
    [organizersImageView setImage:[UIImage imageNamed:@"icon_sponsor_blue"]];
    [scrollView addSubview:organizersImageView];
    [organizersImageView release];
    
    // 举办方的Label
    self.organizersLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 130, 200, 20)];
    //    self.organizersLabel.backgroundColor = [UIColor redColor];
    [scrollView addSubview:self.organizersLabel];
    self.organizersLabel.font = [UIFont systemFontOfSize:12];
    [_organizersLabel release];
    
    // 活动类型的小图标
    UIImageView *styleImageView =[[UIImageView alloc]initWithFrame:CGRectMake(150, 160, 20, 20)];
    [styleImageView setImage:[UIImage imageNamed:@"icon_catalog_blue"]];
    [scrollView addSubview:styleImageView];
    [styleImageView release];
    
    // 活动类型Label
    self.styleLabel = [[UILabel alloc]initWithFrame:CGRectMake(170, 160, 200, 20)];
    //        self.styleLabel.backgroundColor = [UIColor redColor];
    //    self.styleLabel.text = @"";
    self.styleLabel.font = [UIFont systemFontOfSize:12];
    [scrollView addSubview:self.styleLabel];
    [_styleLabel release];
    
    // 活动地址的小图标
    UIImageView *addressImageView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 190, 20, 20)];
    [addressImageView setImage:[UIImage imageNamed:@"icon_spot_blue"]];
    [scrollView addSubview:addressImageView];
    [addressImageView release];
    
    // 活动地址Label
    self.addressLabel = [[UILabel alloc]initWithFrame:CGRectMake(170, 190, 200, 20)];
    //    self.addressLabel.backgroundColor = [UIColor redColor];
    self.addressLabel.font = [UIFont systemFontOfSize:12];
    [self.addressLabel setNumberOfLines:0];
    self.addressLabel.lineBreakMode = NSLineBreakByCharWrapping;
    [scrollView addSubview:self.addressLabel];
    [_addressLabel release];
    
    // 活动介绍Label
    self.introduceLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 250, 120, 36)];
    //    self.introduceLabel.backgroundColor = [UIColor redColor];
    self.introduceLabel.text = @"活动介绍";
    [scrollView addSubview:self.introduceLabel];
    [_introduceLabel release];
    
    // 详情介绍Label
    self.informationLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 300, 375 - 40, 36)];
    //    self.informationLabel.backgroundColor = [UIColor redColor];
    [self.informationLabel setNumberOfLines:0];
    self.informationLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.informationLabel.font = [UIFont fontWithName:@"Arial" size:12];
    //    CGSize size = CGSizeMake(335, 10000);
    //    CGSize labelSize = [self.informationLabel.text sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
    //    [self.informationLabel setFrame:CGRectMake(20, 300, labelSize.width, labelSize.height)];
    [scrollView addSubview:self.informationLabel];
    [_informationLabel release];
}

- (CGFloat)labelAutoSize{
    [self.informationLabel sizeToFit];
    [self.addressLabel sizeToFit];
    [self.nameLabel sizeToFit];
    return self.informationLabel.frame.size.height;
}


@end
